package com.junzhiit.nengji.cms.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.bainaeco.framework.util.JsonUtil;
import com.junzhiit.nengji.cms.service.ChainGoodsImagesService;
import com.junzhiit.nengji.cms.web.vo.ChainGoodsImagesAddVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

@RestController
@RequestMapping("chain/goods/images")
public class ChainGoodsImagesController {
	
	@Autowired
	ChainGoodsImagesService chainGoodsImagesService;

	@RequestMapping(value = "goodsid/{chainGoodsId}", method = RequestMethod.GET)
	public ResultVO findByChainGoodsId(@PathVariable String chainGoodsId) {
		return chainGoodsImagesService.findByChainGoodsId(chainGoodsId);
	}

	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(String goodsImagesAddVOJson) {
		AssertUtil.notBlank(goodsImagesAddVOJson, "goodsImagesAddVOJson is required.");
		List<ChainGoodsImagesAddVO> goodsImagesAddVOs = JsonUtil.toListObject(goodsImagesAddVOJson, ChainGoodsImagesAddVO.class);
		return chainGoodsImagesService.add(goodsImagesAddVOs);
	}

	@RequestMapping(method = RequestMethod.DELETE)
	public ResultVO del(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return chainGoodsImagesService.del(id);
	}
}
